﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;

namespace WeiBo.Model
{
    public static class MessageCenter
    {
        static IDictionary<string, List<string>> SubDic = new Dictionary<string, List<string>>();
        public static void Subscribe(string user, string subUser) {
            if (SubDic.ContainsKey(subUser))
            {
                if (SubDic[subUser].Any(t => t == user))
                {
                    Trace.WriteLine(user+"已经关注了:"+subUser);
                }
                else {
                    SubDic[subUser].Add(user);
                }
               
            }
            else {
                SubDic[subUser] = new List<string>() {
                    user
                };
            }
            Trace.WriteLine(user + "成功关注" + subUser);
        }
        public static void Publish(this string user, string message) {
            if (SubDic.ContainsKey(user)) {
                foreach (var item in SubDic[user])
                {
                    Trace.WriteLine("用户"+user + "发布了信息,通知用户:"+item+"，消息:"+ message);
                }
            }
        }
    }
}